/**
 * 加密工具
 */
import JsEncrypt from 'jsencrypt';
import CryptoJS from 'crypto-js';
//公钥串
const PUB_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCW9Wnjmeie4kFdHC35YxxPxdZi+CEKqMYFFS5C8lU/tNX3rk8qrsjoff+gCS7gY6c/GH1yRYJ8xLL6VcCs5wB8lrJPINL3I8T4MsxHPEVnCzDOtWtbLqfkFRH8o+gxn3ccJJX1CwgTnhaCOv9pGqzuf9RGX8SloFBIlQk+oytWoQIDAQAB";
export default  {
	//MD5加密
	MD5(data){
		return CryptoJS.MD5(data).toString()
	},
	//BASE64加解密
	BASE64: {
		encrypt(data){
			return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))
		},
		decrypt(cipher){
			return CryptoJS.enc.Base64.parse(cipher).toString(CryptoJS.enc.Utf8)
		}
	},
	//RSA加密
	RSA:{
		/**
		 * RSA 加密
		 * @param data String字符串
		 * @returns {string}
		 */
		encrypt(data){
			let jse = new JsEncrypt()
			jse.setPublicKey(PUB_KEY);
			return jse.encrypt(data).toString()
		}
	}
}

